package com.sls.mall.order.web;

import com.sls.mall.order.entity.OmsOrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller
public class IndexController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/confirm.html")
    public String confirm(){
        return "confirm";
    }

    @GetMapping("/list.html")
    public String list(){
        return "list";
    }

    @GetMapping("/detail.html")
    public String detail(){
        return "detail";
    }

    @GetMapping("/pay.html")
    public String pay(){
        return "pay";
    }

    @ResponseBody
    @GetMapping("/orderCreate")
    public String createOrder(){
        OmsOrderEntity entity = new OmsOrderEntity();
        entity.setOrderSn(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order", entity);
        return "ok";
    }

}
